package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Asin
 */
public interface CategoryMapper {
    /**
     * 查询所有Category
     * @return
     */
    @Select("select * from category")
    List<Category> findAll();

    /**
     * 新增菜品或者分类
     * @param category
     * @return
     */
    @Insert("insert into category values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    int addCategory(Category category);

    /**
     * 更新菜品或者套餐
     * @param category
     * @return
     */
    int updateCategory(Category category);

    /**
     * 根据名称查询分类
     * @param name
     * @return
     */
    @Select("select * from category where name=#{name}")
    Category findCategoryByName(String name);

    @Delete("delete from category where id = #{id}")
    int deleteCategoryById(long id);


    List<Category> findCategoryByType(Integer type);

    @Select("select name from category where id = #{id}")
    String findCategoryNameById(long id);
}
